import React, { Component } from 'react'
import MyContext from './MyContext'
import Child from './Child'

export default class Parent extends Component {

  constructor() {
    super();
    this.state = {
      name: '马鹏程',
      age: 18
    }
  }

  change=(age)=> {
    this.setState({
      age
    })
  }

  static contextType = MyContext;

  render() {
    console.log(this.context)
    return (
      <div>
        <MyContext.Provider value={{
          name: this.state.name,
          age: this.state.age,
          change:this.change
        }}>
          <Child></Child>
        </MyContext.Provider>
      </div>
    )
  }
}
